package com.example.mychat.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class Comment implements Serializable {
    @TableId(type = IdType.ASSIGN_ID)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    private String username; //评论者的用户名

    private String respondedName; //被回复人的用户名，为空时表示评论主体消息

    private String text; //评论内容
    @JsonSerialize(using = ToStringSerializer.class)
    private Long messageId; //评论的消息id

    private Date commentTime; //评论时间

    public Comment() {

    }

    public Comment(String username, String text, Long messageId) {
        this.username = username;
        this.text = text;
        this.messageId = messageId;
        this.commentTime = new Date();
    }

    public Comment(String username, String respondedName, String text, Long messageId) {
        this.username = username;
        this.respondedName = respondedName;
        this.text = text;
        this.messageId = messageId;
        this.commentTime = new Date();
    }
}
